﻿using System;
using weka.core;
using weka.core.converters;
using java.io;

namespace OMC.Classification
{
    /// <summary>
    /// This class can manage all the parts of loading data from a file.
    /// </summary>
    class DataLoader
    {
        private ArffLoader loader;
        private Instances rawData;
        private String filePath;

        /// <summary>
        /// The constructor to generate an object.
        /// </summary>
        /// <param name="path">
        /// the file Path inkl. filename of the arff data file
        /// for example: -> C:\Program Files\Microsoft Office\Office14\BAMailClassData\
        /// if you chose the folowing string as inFilePath: "./BAMailClassData/ARFF/data.arff"
        /// </param>
        public DataLoader(String path)
        {
            this.filePath = path;
        }

        /// <summary>
        /// This method loads the arff data from a file
        /// </summary>
        /// <returns>
        /// the returned data are from type of Instances
        /// </returns>
        public Instances Load()
        {
            loader = new ArffLoader();
            rawData = null;
            try
            {
                loader.setSource(new File(filePath));
                rawData = loader.getDataSet();
                rawData.setClassIndex(rawData.numAttributes() - 1);
            }
            catch (Exception ex)
            {
                Utils.Debug.LogException(ex);
            }
            return rawData;
        }
    }
}